/**
 * Lighthouse CI 配置
 * 用于移动端性能监控和Web Vitals检测
 */
module.exports = {
  ci: {
    collect: {
      numberOfRuns: 3, // 运行3次取平均值
      startServerCommand: 'npm run preview',
      url: [
        'http://localhost:4173/',
        'http://localhost:4173/login',
        'http://localhost:4173/hot-radar',
        'http://localhost:4173/conversation',
        'http://localhost:4173/dashboard',
      ],
      settings: {
        // 移动端设备模拟
        formFactor: 'mobile',
        screenEmulation: {
          mobile: true,
          width: 375,
          height: 667,
          deviceScaleFactor: 2,
          disabled: false,
        },
        // 模拟3G网络（Fast 3G）
        throttling: {
          rttMs: 150,
          throughputKbps: 1600,
          requestLatencyMs: 150,
          downloadThroughputKbps: 1600,
          uploadThroughputKbps: 750,
          cpuSlowdownMultiplier: 4,
        },
        // 其他设置
        onlyCategories: ['performance', 'accessibility', 'best-practices', 'seo'],
        skipAudits: ['uses-http2'], // 跳过某些在开发环境不适用的审计
      },
    },
    assert: {
      preset: 'lighthouse:recommended',
      assertions: {
        // 性能指标
        'categories:performance': ['error', { minScore: 0.9 }],
        'categories:accessibility': ['error', { minScore: 0.9 }],
        'categories:best-practices': ['error', { minScore: 0.9 }],
        'categories:seo': ['warn', { minScore: 0.85 }],

        // Core Web Vitals
        'first-contentful-paint': ['warn', { maxNumericValue: 2000 }],
        'largest-contentful-paint': ['error', { maxNumericValue: 2500 }],
        'cumulative-layout-shift': ['error', { maxNumericValue: 0.1 }],
        'total-blocking-time': ['warn', { maxNumericValue: 300 }],
        'interactive': ['warn', { maxNumericValue: 3800 }],
        'speed-index': ['warn', { maxNumericValue: 3400 }],

        // 资源优化
        'uses-text-compression': 'warn',
        'uses-optimized-images': 'warn',
        'modern-image-formats': 'warn',
        'uses-responsive-images': 'warn',
        'offscreen-images': 'warn',

        // JavaScript优化
        'unused-javascript': 'warn',
        'unused-css-rules': 'warn',
        'unminified-javascript': 'warn',
        'unminified-css': 'warn',

        // 无障碍性
        'color-contrast': 'warn',
        'image-alt': 'warn',
        'button-name': 'warn',
        'link-name': 'warn',

        // 最佳实践
        'errors-in-console': 'warn',
        'no-vulnerable-libraries': 'error',
        'charset': 'error',
        'viewport': 'error',
      },
    },
    upload: {
      target: 'temporary-public-storage',
      // 如果要上传到Lighthouse CI Server，配置如下：
      // target: 'lhci',
      // serverBaseUrl: 'https://your-lhci-server.com',
      // token: process.env.LHCI_TOKEN,
    },
  },
}
